//
// Created by dxyinme on 2021/11/7.
//

#include "thread_pool.h"

#include <iostream>

// calc a ** b % mod
class CalcTask : public CppTools::ThreadPool::ThTask {
public:

  int a{}, b{}, mod{};

  int ret{};

  CalcTask(int id) :
    ThTask(id) {}

  void TaskDo() override {
    int s = 1;
    for (int i = 0; i < b; i ++) {
      s = s * a % mod;
    }
    ret = s;
  }
};

int main(int argc, char ** argv) {
  CppTools::ThreadPool::ThPool thp(4);
  std::vector<std::shared_ptr<CalcTask>> ptr_v;
  for (int i = 0; i < 10; i++) {
    auto now_ptr = std::make_shared<CalcTask>(i);
    now_ptr->a = i;
    now_ptr->b = 1000000 - i * 2;
    now_ptr->mod = 1e4 + 7;
    ptr_v.emplace_back(now_ptr);
    thp.Commit(ptr_v.back());
  }
  for (int i = 0; i < 10; i++) {
    ptr_v[i]->Wait();
    std::cout << "task :" << i << std::endl;
    std::cout << ptr_v[i]->ret << std::endl;
    std::cout << ptr_v[i]->WorkMessage() << std::endl;
  }
  return 0;
}